package com.leng.admin.config;

import com.leng.admin.service.IMenuService;
import com.leng.admin.service.IRoleService;
import com.leng.common.core.entity.admin.domain.AdminUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

/**
 * 用户权限处理
 *
 * @author Community
 */
@Component
public class PermissionService
{
    @Autowired
    private IRoleService roleService;

    @Autowired
    private IMenuService menuService;

    /**
     * 获取角色数据权限
     *
     * @param user 用户信息
     * @return 角色权限信息
     */
    public Set<String> getRolePermission(AdminUser user)
    {
        Set<String> roles = new HashSet<String>();
        // 管理员拥有所有权限
        if (user.getUno() != null && "1" .equals(user.getUno()))
        {
            roles.add("admin");
        }
        else
        {
            roles.addAll(roleService.selectRolePermissionByUserId(user.getUno()));
        }
        return roles;
    }

    /**
     * 获取菜单数据权限
     *
     * @param user 用户信息
     * @return 菜单权限信息
     */
    public Set<String> getMenuPermission(AdminUser user)
    {
        Set<String> perms = new HashSet<String>();
        // 管理员拥有所有权限
        if ( user.getUno() != null && "1" .equals(user.getUno()))
        {
            perms.add("*:*:*");
        }
        else
        {
//            perms.addAll(menuService.selectMenuPermsByUserId(user.getUno()));
        }
        return perms;
    }
}
